<?php
// +----------------------------------------------------------------------
// | Description: about us
// +----------------------------------------------------------------------
// | Author: orchief
// +----------------------------------------------------------------------
// | Date: 2018-03-06 13:37:11
// +----------------------------------------------------------------------

namespace App\Model;

use App\Common\Model;

class Order extends Model
{
    protected $fuzzyConditions = ['productName', 'username', 'shopName'];
    protected $clearConditions = ['userId', 'totalPrice', 'productNum', 'shopId', 'orderStatus', 'productId', 'type', 'province', 'city', 'hometown', 'detailAddress'];
    protected $returnFields = '';
    protected $rangeConditions = ['createTime', 'shipTime'];
    protected $union_fuzzyConditions = null;
    protected $foreignConditions = null;
    protected $name = 'pudu_orders';
    /**
     * [enableDatas 批量启用、禁用]
     * @AuthorHTL
     * @DateTime  2017-02-11T21:01:58+0800
     * @param     string                   $ids    [主键数组]
     * @param     integer                  $status [状态1启用0禁用]
     * @param     [boolean]                $delSon [是否删除子孙数组]
     * @return    [type]                           [description]
     */
    public function enableDatas($ids = [], $status = 1, $delSon = false)
    {
        if (empty($ids)) {
            $this->error = '操作失败';
            return false;
        }

        // 查找所有子元素
        if ($delSon && $status === '0') {
            foreach ($ids as $k => $v) {
                $childIds = $this->getAllChild($v);
                $ids = array_merge($ids, $childIds);
            }
            $ids = array_unique($ids);
        }
        try {
            $this->where($this->getPk(), 'in', $ids)->setField('orderStatus', $status);
            return true;
        } catch (\Exception $e) {
            $this->error = $e->getMessage();
            return false;
        }
    }
}
